<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content">简历库</block>
			<block slot="right">
				<image @click="showFun" class="nav-right-image" src="@/static/images/nav_opt.png"></image>
			</block>
		</cu-custom>

		<view class="page-content" :style="{height:this.ContentArea+'px',paddingTop:'30rpx'}">
			<view class="page-search">

				<view class="search">
					<view class="search-left">
						<image src="@/static/images/search.png" mode="aspectFit" />
					</view>
					<input class="search-center" type="text" placeholder="输入用户进行搜索"
						placeholder-class="search-placeholder" v-model="searchValue" @blur="onRefresh">
				</view>
			</view>
			<view class="page-content-main">
				<scroll-view class="list" :scroll-y='true' :refresher-enabled="true" :refresher-triggered="refreshing"
					@refresherrefresh="onRefresh" :refresher-background="'#F9F9F9'" @scrolltolower="onEndReached">
					<uni-swipe-action right-options="rightOptions">
						<uni-swipe-action-item v-for="(item, index) in dataList" :key="index">
							<!-- <view style=" position: relative; height: 92px; background-color: #F9F9F9; padding: 15rpx; border-radius: 15px;display: flex; margin-top: 15px;">
							<view style="margin: 5px 0 0 15px ;">
								<view>
									<text style="font-size: 18px; font-weight: bold;">
										{{item.name}}
									</text>
								</view>
								<view
									style="border-radius: 40rpx 40rpx 40rpx 40rpx; background-color: rgba(52,167,89,0.14); min-width: 140px; padding:1px 10px; margin-top: 9rpx;">
									<text style="color:#34A759;">
										联系电话：{{item.phone}}
									</text>
								</view>
								<view
									style="border-radius: 40rpx 40rpx 40rpx 40rpx; background-color: rgba(52,167,89,0.14); min-width: 140px; padding:1px 10px; margin-top: 10rpx;">
									<text style="color:#34A759;">
										应聘形式：{{item.applicationType_dictText}}
									</text>
								</view>
							</view>
						</view> -->
							<view class="list-item" :style="isBatchChoose?'margin-left: 80rpx;':''">
								<view class="list-item-leftCenter">
									<!-- <view class="list-item-left">
									<image :src="item.avatar" mode="aspectFit" />
								</view> -->
									<view class="list-item-center">
										<view class="list-item-row">
											<view class="list-item-name">
												{{item.name}}
											</view>
										</view>
										<view class="list-item-row">
											<view class="list-item-row-icon">
												<image src="@/static/images/blackListType.png" mode="aspectFit" />
											</view>
											<view class="list-item-row-title">人才状态：</view>
											<view class="list-item-row-value">{{item.resumeStatus_dictText}}</view>
											<!-- <view class="list-item-row-icon2">
											<image src="@/static/images/blackListBtn.png" mode="aspectFit" />
										</view> -->
										</view>
										<view class="list-item-row">
											<view class="list-item-row-icon">
												<image src="@/static/images/blackListInfo.png" mode="aspectFit" />
											</view>
											<view class="list-item-row-title">招聘形式：</view>
											<view class="list-item-row-value">{{item.applicationType_dictText}}</view>
										</view>

									</view>
								</view>
								<view class="list-item-btn">
									<image src="@/static/images/blackListBtn.png" mode="aspectFit"
										@click="toDetails(item)" />
								</view>
							</view>
							<template v-slot:right>
								<view
									style="position: relative;margin-top:30rpx;margin-left:20rpx;background-color: #F9F9F9;border-radius: 15px;padding:10rpx 30rpx">
									<view @click="edit(item)"
										style="margin-top: 0rpx; border-radius: 30rpx;background-color: rgba(255, 173, 4, 1);padding:8rpx 30rpx;color: #FFFFFF;font-size: 20rpx;">
										编辑
									</view>
									<view @click="toDetails(item)"
										style="border-radius: 30rpx;background-color: rgba(69, 145, 254, 1);padding:8rpx 30rpx;margin-top: 10rpx; margin-bottom: 15rpx;color: #FFFFFF;font-size: 20rpx;">
										详情
									</view>
									<view @click="toDelete(item.id)"
										style="border-radius: 30rpx;background-color: rgba(220, 31, 31, 1);padding:8rpx 30rpx;margin-top: -5rpx;margin-bottom: 15rpx;color: #FFFFFF;font-size: 20rpx;">
										删除
									</view>
								</view>
							</template>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</scroll-view>
			</view>
			<uni-popup type="center" ref="addWindow" background-color="#fff" :mask-click="false">
				<view
					style="background-color: #FFFFFF;padding: 11rpx 30rpx;width: 580rpx;height: 1170rpx;border-radius: 42rpx;">
					<view style="margin-top: 28rpx;margin-left: 15rpx;">
						<text class="submit-text">{{windowFlag}}</text>
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>姓名：</text>
						<input v-model="name" placeholder="请输入姓名" name="input" style="font-size: 25rpx;"></input>
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>身份证号：</text>
						<input v-model="idCard" placeholder="请输入身份证号" name="input" style="font-size: 25rpx;"></input>
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>联系电话：</text>
						<input v-model="phone" placeholder="请输入联系电话" name="input" style="font-size: 25rpx;"></input>
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>性别：</text>
						<my-select range-key="text" value-key="value" dict-code="sex" v-model="sex" />
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>出生年月：</text>
						<picker mode="date" :value="birth" @change="DateChange">
							<view style="text-align:right;line-height: 15px;">
								{{birth != '' ? birth : '请选择'}}
							</view>
						</picker>
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>应聘形式：</text>
						<my-select range-key="text" value-key="value" dict-code="application_type"
							v-model="applicationType" />
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>人才状态：</text>
						<my-select range-key="text" value-key="value" dict-code="resume_status"
							v-model="resumeStatus" />
					</view>
					<view class="cu-form-group"
						style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 20rpx;">
						<text>附件：</text>
						<uni-file-picker style="margin-left: 200rpx;" limit="5" file-mediatype="all" @select="select"
							@delete="deleteFile"></uni-file-picker>
					</view>
					<button style="background-color: rgba(217, 217, 217, 1);
								color: rgba(86, 85, 85, 1); margin-top: 30rpx;padding: 2rpx 85rpx; display: inline-block; "
						@click="rejectCancel">取消</button>
					<button style="background-color: rgba(69, 145, 254, 1);
					color: rgba(255, 255, 255, 1);margin-left:34rpx; display: inline-block;padding: 2rpx 85rpx; "
						@click="rejectSure">确定</button>
				</view>
			</uni-popup>
			<uni-popup ref="deletePopup" background-color="#fff" :mask-click="false">
				<view
					style="text-align: center;background-color: #FFFFFF;padding: 11rpx;width: 580rpx;height: 470rpx;border-radius: 42rpx;">
					<view class="submit-item">
						<image class="submit-icon" src="@/static/images/deleteIcon.png" />
					</view>
					<view style="margin-top: 28rpx;">
						<text class="submit-text">确定删除该列表吗</text>
					</view>
					<br>
					<view style="display: flex;">
						<button @click="sureDelete" style="border-radius: 20rpx; background-color: red;
								color: rgba(255, 255, 255, 1);width: 230rpx;margin-top: 50rpx;">确定</button>
						<button @click="cancelDelete" style="border-radius: 20rpx; background-color: gray;
								color: rgba(255, 255, 255, 1);width: 230rpx;margin-top: 50rpx;">取消</button>
					</view>
				</view>
			</uni-popup>
		</view>

		<view class="fun-wrap" v-show="isShowFun" @click="hideFun">
			<view class="fun-box" :style="{top:this.CustomBar+'px'}">
				<view class="fun-item" @click.stop="gotoAdd">
					<image class="fun-icon" src="@/static/images/addIcon.png" />
					<text class="fun-text">新增</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import moment from 'moment';
	import configService from '@/common/service/config.service.js'
	export default {
		data() {
			return {
				CustomBar:0,
				ContentArea:0,
				isBatchChoose:false,
				idCard: '',
				name: '',
				phone: '',
				birth: '',
				sex: '',
				applicationType: '',
				resumeStatus: '',
				windowFlag: '',
				fileList: [],
				returnFileName: '',
				searchValue: '',
				dataList: [],
				refreshing: true,
				isShowFun: false,
				pageSize: 10,
				pageNo: 1,
				total: 0,
				ids: '',
			}
		},
		watch: {},
		mounted() {
			this.onRefresh()
		},
		created() {
			//this.getList()
		},
		computed: {},
		methods: {
			async onRefresh() {
				try {
					this.refreshing = true
					const res = await this.getList(1);
					this.refreshing = false
					this.pageNo = 1
					this.dataList = res?.data?.result?.records
					this.total = res?.data?.result?.total
					console.log('this.dataList',this.dataList)
				} catch (e) {
					this.refreshing = false
					console.log(e)
				}
			},
			async onEndReached() {
				console.log("获取列表2==" + this.pageNo * this.pageSize + "total==" + this.total)
				try {
					if (this.pageNo * this.pageSize < this.total) {
						console.log("获取列表3")
						const res = await this.getList(this.pageNo + 1);
						this.pageNo += 1;
						this.dataList = this.dataList.concat(res?.data?.result?.records)

						this.total = res?.data?.result?.total
					}
				} catch (e) {
					console.log(e)
				}
			},
			async getList(pageNo) {
				console.log("获取列表")
				let companyId = ''
				uni.getStorage({
					key:'Auth_Company_Id',
					success: function (res) {
					console.log('rrr',res.data);
					companyId = res.data
				   },
					fail: function (error) {
					console.log('获取数据失败：', error);
					companyId = ''
				   }
				});
				let params = {}
				if (this.createTime) {
					params = {
						pageNo: pageNo,
						pageSize: this.pageSize,
						// company: localStorage.getItem('Auth_Company_Id'),
						company: companyId,
						name: this.searchValue || '',
						realname: this.searchValue,
						createTime: this.createTime + " 00:00:00",
						approvalStatus: this.approvalStatus
					}
				} else {
					params = {
						pageNo: pageNo,
						pageSize: this.pageSize,
						// company: localStorage.getItem('Auth_Company_Id'),
						company: companyId,
						name: this.searchValue || '',
						realname: this.searchValue,
						approvalStatus: this.approvalStatus
					}
				}
				console.log('简历库',params)
				return await this.$http.get("/crm_resume_library/crmResumeLibrary/list", {
					params: params
				})
				// .then(res => {
				// 	if (res.data.success) {
				// 		let records = res.data.result.records
				// 		this.dataList = records
				// 	}
				// })
			},
			clearSearch() {
				this.searchValue = ''
			},
			searchBtn() {
				this.getList()
			},
			showFun() {
				this.isShowFun = true
			},
			hideFun() {
				this.isShowFun = false
			},
			DateChange(e) {
				this.birth = e.detail.value
			},
			gotoAdd() {
				this.windowFlag = '新增'
				this.isShowFun = false
				this.$refs.addWindow.open('center')
				this.idCard = ''
				this.name = ''
				this.phone = ''
				this.sex = ''
				this.birth = ''
				this.applicationType = ''
				this.resumeStatus = ''
				this.fileList = []
				this.returnFileName = ''
			},
			edit(item) {
				this.editId = item.id
				this.windowFlag = '编辑'
				this.$refs.addWindow.open('center')
				this.name = item.name
				this.phone = item.phone
				this.sex = item.sex
				this.birth = item.birth
				this.applicationType = item.applicationType
				this.resumeStatus = item.resumeStatus
				this.idCard = item.idCard
			},
			toDetails(item) {
				uni.navigateTo({
					url: '/pages/resume/resumeDetails/index?detailsObj=' + JSON.stringify(item)
				})
			},
			toDelete(id) {
				this.deleteIds = id
				this.$refs.deletePopup.open('center')
			},
			sureDelete() {
				this.$http.delete('/crm_resume_library/crmResumeLibrary/delete?id=' +
						this.deleteIds)
					.then(res => {
						if (res.data.success) {
							this.$tip.toast('删除成功')
							this.getList()
							this.$refs.deletePopup.close()
						} else {
							this.$tip.toast('删除失败')
						}
					}).catch(() => {
						this.$tip.loaded();
						this.$tip.toast('删除失败')
					});
			},
			cancelDelete() {
				this.$refs.deletePopup.close()
			},
			rejectSure() {
				this.uploadFileOne(this.fileList);
				setTimeout(() => {
					if (this.windowFlag == '新增') {
						this.$http.post('/crm_resume_library/crmResumeLibrary/add', {
								"applicationType": this.applicationType,
								"birth": this.birth,
								"idCard": this.idCard,
								"name": this.name,
								"phone": this.phone,
								"resumeStatus": this.resumeStatus,
								"sex": this.sex,
								"annex": this.returnFileName,
							})
							.then(res => {
								if (res.data.success) {
									this.getList()
									this.$refs.addWindow.close()
								} else {
									this.$tip.toast(res.data.message)
								}
							}).catch(() => {
								this.$tip.loaded();
								this.$tip.toast('提交失败')
							});
					} else {
						this.$http.put('/crm_resume_library/crmResumeLibrary/edit', {
								"id": this.editId,
								"applicationType": this.applicationType,
								"idCard": this.idCard,
								"birth": this.birth,
								"name": this.name,
								"phone": this.phone,
								"resumeStatus": this.resumeStatus,
								"sex": this.sex,
								"annex": this.returnFileName,
							})
							.then(res => {
								if (res.data.success) {
									this.getList()
									this.$refs.addWindow.close()
								} else {
									this.$tip.toast(res.data.message)
								}
							}).catch(() => {
								this.$tip.loaded();
								this.$tip.toast('提交失败')
							});
					}
				}, 500)

			},
			rejectCancel() {
				this.$refs.addWindow.close()
			},
			select(e) {
				console.log('选择文件：', e)
				// this.imageValue.push(e.tempFilePaths[0])
				this.fileList.push(e.tempFilePaths[0])
			},
			deleteFile(e) {
				console.log('移除文件：', e)
				this.fileList.splice(e.tempFilePaths, 1)
			},
			uploadFileOne(fileList) {
				const that = this
				fileList.forEach((item) => {
					that.$http.upload(that.$config.apiUrl + '/sys/common/upload', {
						filePath: item,
						name: 'file'
					}).then(res => {
						that.returnFileName = res.data.message
					}).catch(err => {
						that.$tip.error(err.data.message)
					});
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	image {
		width: 100%;
		height: 100%;
	}

	.blackList {
		height: 100%;
		overflow: hidden;
	}

	.page-search {
		padding-left: 34rpx;
		margin-bottom: 12rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.search {
		width: 680rpx;
		height: 86rpx;
		background-color: rgba(249, 249, 249, 1);
		border-radius: 60rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 24rpx;
		padding-right: 24rpx;

		.search-left {
			width: 28rpx;
			height: 28rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.search-center {
			margin-left: 22rpx;
		}

		.search-placeholder {
			font-size: 28rpx;
			font-weight: 400;
			color: #7C7C7C;
		}


	}

	.filter-btn {
		width: 40rpx;
		height: 40rpx;
		margin-right: 42rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.page-content-main {
		height: calc(100% - 12rpx - 86rpx);
		border-top-left-radius: 64rpx;
		border-top-right-radius: 64rpx;
		padding: 26rpx 34rpx 0 34rpx
	}

	.select-box {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;

	}

	.select {
		width: 160rpx;
		height: 74rpx;
		border-radius: 60rpx;
		background-color: #4591FE;
		margin-bottom: 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin-right: 12px;
		position: relative;

		.select-value {
			font-size: 28rpx;
			font-weight: 400;
			color: #FFFFFF;
			margin-right: 18rpx;
		}

		.select-icon {
			width: 22rpx;
			height: 22rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			position: absolute;
			right: 20rpx;
			top: 25rpx;
		}
	}

	.list {
		height: calc(100vh - 450rpx);
	}

	.list-item {
		border-radius: 28rpx;
		background-color: #FFFFFF;
		padding: 26rpx 24rpx 28rpx 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin-bottom: 26rpx;
		position: relative;

		.list-item-leftCenter {
			display: flex;
			flex-direction: row;
		}

		.list-item-left {
			width: 86rpx;
			height: 86rpx;
			margin-right: 26rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.list-item-center {
			.list-item-row {
				display: flex;
				flex-direction: row;
				margin-bottom: 20rpx;

				.list-item-name {
					color: #101317;
					font-size: 32rpx;
					margin-right: 16rpx;
				}

				.list-item-sex {
					width: 106rpx;
					height: 42rpx;
					border-top-right-radius: 40rpx;
					border-bottom-right-radius: 40rpx;
					border-bottom-left-radius: 20rpx;
					background-color: rgba(234, 171, 78, 0.35);
					line-height: 42rpx;
					text-align: center;
					color: rgba(255, 173, 4, 1);
					font-size: 24rpx;
				}

				.list-item-row-icon {
					width: 38rpx;
					height: 38rpx;
					margin-right: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.list-item-row-icon2 {
					width: 38rpx;
					height: 38rpx;
					margin-left: 386rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.list-item-row-title,
				.list-item-row-value {
					font-size: 24rpx;
					font-weight: 400;
					color: #101317;
					line-height: 38rpx;
				}

			}
		}

		.list-item-btn {
			width: 36rpx;
			height: 36rpx;
			margin-top: 56rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.list-item-tab {
			width: 132rpx;
			height: 56rpx;
			text-align: center;
			line-height: 56rpx;
			background-color: rgba(69, 145, 254, 0.4);
			position: absolute;
			top: 0;
			right: 0;
			border-top-right-radius: 26rpx;
			border-bottom-left-radius: 20rpx;
		}

		.list-item-tab-text {
			font-size: 26rpx;
			color: rgba(69, 145, 254, 1)
		}
	}

	.nav-right-image {
		width: 80rpx;
		height: 80rpx;
		margin-left: 15px;
	}

	.fun-wrap {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(3, 3, 3, 0.28);
		z-index: 10000;
	}

	.fun-box {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
		width: 556rpx;
		height: 444rpx;
		border-top-left-radius: 42rpx;
		border-bottom-left-radius: 42rpx;
		border-bottom-right-radius: 42rpx;
		position: absolute;
		right: 74rpx;
		background-color: #FFFFFF;
		padding-top: 35rpx;
	}

	.fun-item {
		width: 185rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-bottom: 44rpx;
	}

	.fun-icon {
		width: 92rpx;
		height: 92rpx;
		margin-bottom: 22rpx;
	}

	.cu-form-group {
		background-color: transparent;
	}

	::v-deep {
		.cu-form-group uni-picker .picker {
			color: #FFFFFF;
		}

		.cu-form-group uni-picker::after {
			opacity: 0;
		}
	}

	.textView {
		margin-left: 25px;
		font-size: 10px;
		margin-top: 5px;
	}

	.listText {
		width: 148rpx;
		height: 24rpx;
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #000000;
		line-height: 24rpx;
	}

	.submit-icon {
		width: 118rpx;
		height: 118rpx;
		margin-top: 58rpx;
	}

	.mySelect {
		position: relative;
		background-color: #4591FE;
		border-radius: 60rpx;
		height: 74rpx;

		.mySelect-value {
			position: inherit;
			margin-left: 10rpx;
			margin-right: -25rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #FFFFFF;
		}

		.mySelect-icon {
			width: 22rpx;
			height: 22rpx;
			position: absolute;
			top: 30%;
			right: 18%;
		}
	}
</style>